import pymysql
# # 1. 导入pymysql
# # connect连接
# db = pymysql.connect(host='47.103.126.208',port=3306,user='thy_62',password='123456',database='mall')
# # 创建游标
# cursor= db.cursor()
# # 3.执行sql语句
# cursor.execute('select * from ls_order')
# # 4.拿sql语句执行的结果 fach拿
# print(cursor.fetchone())
# print(cursor.fetchall())
class ConnectMySQL:
    def __init__(self,host='47.103.126.208', port=3306, user='thy_62', password='123456', database='mall'):
        db = pymysql.connect(host=host,port=port,user=user,password=password,database=database)
        self.cursor = db.cursor()
    def excute_sql(self,sql,fetch = 'one'):
        self.cursor.execute(sql)# 执行sql语句
        if fetch == 'one':#输出一种结果
            return self.cursor.fetchone()
        elif fetch == 'all':#输出所有结果
            return self.cursor.fetchall()
